package com.zlp.mymapviewproject.mymapview;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.sun.shine.myrotation.view.RotatView_add_new_point;
import net.xxhong.rosclient.R;
import java.io.IOException;
import java.io.InputStream;

public class MyMapPointWithTitleView_xuanfu_mark extends LinearLayout {
    public static final int MARK_wall = -3;
    public static final int MARK_move = -2;
    public static final int MARK_POINT = -1;
    public static final int RED_POINT = 0;
    public static final int BLUE_POINT = 1;
    public static final int blueviolet_POINT = 2;
    public static final int darksalmon_POINT = 3;
    public static final int limegreen_POINT = 4;
    public static final int mediumaquamarine_POINT = 5;
    RotatView_add_new_point pointIcon;
    private TextView pointTitle;
    private Context context;
    private double firstX;
    private double firstY;
    private double borderTop;
    private double borderLeft;
    private int state;
    private String title;
    private boolean isTitleShow;
    public MyMapPointWithTitleView_xuanfu_mark(Context context) {
        super(context);
        init();
    }

    public MyMapPointWithTitleView_xuanfu_mark(Context context, double pointX, double pointY, int state, boolean isTitleShow, String title) {
        super(context);
        this.context = context;
        this.firstX = pointX;
        this.firstY = pointY;
        this.state = state;
        this.title = title;
        this.isTitleShow = isTitleShow;
        init();
    }

    public void setFirstXShow(float x) {
        x -= borderLeft;
        setX(x);
    }

    public void setFirstYShow(float y) {
        y -= borderTop;
        setY(y);
    }


    public void init() {
        View view = LayoutInflater.from(getContext()).inflate(R.layout.view_mymap_point_with_direction_add_new_point, this);
        pointIcon=(RotatView_add_new_point) findViewById(R.id.pointIcon);
        pointTitle = (TextView) view.findViewById(R.id.pointTitle);
        setPointIcon();
        pointTitle.setText(title);
        measureBorder();
    }

    private void measureBorder() {
        int height = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
        int width = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
        this.pointIcon.measure(width, height);
        this.pointTitle.measure(width, height);
        this.measure(width, height);
        if (!isTitleShow) {
            pointTitle.setVisibility(INVISIBLE);
        } else {
            pointTitle.setVisibility(VISIBLE);
        }
        this.borderLeft = this.pointIcon.getMeasuredWidth() / 2;
        this.borderTop = this.pointIcon.getMeasuredHeight()/2 ;
    }


    private void setPointIcon() {
        String pointPictureName;
        switch (this.state) {
            case MARK_wall:
                pointPictureName = "PointIcon_wall.png";
            case MARK_move:
                pointPictureName = "PointIcon_move.png";
                break;
            case MARK_POINT:
                pointPictureName = "PointIcon_mark.png";
                break;
            case RED_POINT:
                pointPictureName = "PointIcon_red.png";
                break;
            case BLUE_POINT:
                pointPictureName = "PointIcon_blue.png";
                break;
            case blueviolet_POINT:
                pointPictureName = "PointIcon_blueviolet.png";
                break;
            case darksalmon_POINT:
                pointPictureName = "PointIcon_darksalmon.png";
                break;
            case limegreen_POINT:
                pointPictureName = "PointIcon_limegreen.png";
                break;
            case mediumaquamarine_POINT:
                pointPictureName = "PointIcon_mediumaquamarine.png";
                break;
            default:
                pointPictureName = "PointIcon_default.png";
                break;
        }
        InputStream open = null;
        try {
            open = getResources().getAssets().open(pointPictureName);
        } catch (IOException e) {
            e.printStackTrace();
        }
        this.pointIcon.setRotatDrawableResource_bitmap(BitmapFactory.decodeStream(open));
    }

    public double getFirstX() {
        return firstX;
    }

    public double getFirstY() {
        return firstY;
    }

    public float getState() {
        return state;
    }

    public String getTitle() {
        return title;
    }

    public RotatView_add_new_point  getpointIcon() {
        return pointIcon;
    }

}
